<?php 
class Admin_LoginController extends Zend_Controller_Action{ 
	public function init(){
		$this->_sess = new Zend_Session_Namespace();
		$this->_helper->layout->setLayout('login');
	}
	public function indexAction(){
		if($this->_request->isPost()){
			$email = $this->_request->getPost('email');
			$password = $this->_request->getPost('password');
			$mode = new Admin_Model_Login;
			
			$data = $mode->check_login($email,$password);
			if($data==NULL)
			{
				$this->view->error = 'Login Error';
			}
			else
			{
				$session = array(
						'id'		=> 	$data[0]['id'],
						'group'		=> 	$data[0]['id_group'],
						'email'		=>	$data[0]['email'],
						'fullname'	=>	$data[0]['fullname'],
						'address'	=>	$data[0]['address'],
						'phone'		=>	$data[0]['phone'],
						'birthday'	=>	$data[0]['birthday'],
						'avatar'	=> 	$data[0]['avatar']
				);
				$this->_sess->session = $session;
				$this->_helper->redirector('index','index','admin');
			}
		}
	}
	public function logoutAction(){
		unset($this->_sess->session);
		$this->_helper->redirector('index','login','admin');
	}
}
